moved all code into functions/classes