fixes #125 #76 & #82

@settinghead please review and merge
Fix for #125 #76 & #82 #146