set 'quit on any error'
moved code into functions