moved all code inside functions