Cleanup and reorganisation of code base