Fixes #45 and #17

#17 could do with more testing on more than my development system.