Added the start of the admin functionality and refactored a lot of the code - thanks Martin