Tidying up code following pull request - still some issues to fix