tidying dramatically and moving logic in machine to reusable chunks. renaming and harmonisation of naming patterns