fixes #125 #76 & #82

@settinghead please review and merge