Cleaning up

No new functionality, just organised and simplified everything, and added a small bit of documentation