compiler optimising and refactor