Bug fixes and improvements. Closes #15. Closes #16.