Code refactor, update compilation script