Refactor code to compile at last