Refactor compile script

Closes #4