tidy up and refactoring
Merge pull request #1 from samatt/master

tidy up and refactoring