Fix for #23 and other bugs
Merge branch 'bugfix'