Refactoring compile command

- reduce nested callbacks
- break down functions