Optimise code, refactor code, fix naming issues