bug fixes

bug fixes and code tidy up to better fit with MVC