Tidy code and create package, fixes #3