Added some more functions and tidying up