Fix bugs

This closes issues #6, #7, #8, #9 and #10.