Fix indentation issue and optimise code