=========================== Bunch of fixes for issues pointed on codereview page by Brecht and Campbell.