Bugfixing and general cleanup (#7)