Various fixes and cleanup (pull request)

See #13