All major functions are working now. Needs some tidying up and maybe some better documentation :)