Update compile script:

- Better readability
- Escape vars where need
- General bug fixing