Add debug mode, refactor code into functions.