added loads of functionality, some clean up, comments