Bug fixes, fixes #10, #11, #1