Add missing includes and tidy up
Clean up and restructure sources