optimise code structure