Various cleanups

This pullrequest collects the various cleanup patches I collected while working on #20. These should be the easy ones to review and the shouldn't really change any code (though of course I haven't been able to test all of the possible environments).