Fixes #32 and other issues