Tidied code
Cleanup and refactoring