Programme running as it should. Needs refactoring