Fix some bugs, simplify the code and some layout changes for code guidelines
Merge pull request #356 from timschofield/develop

Fix some bugs, simplify the code and some layout changes for code guidel...