Broke code into functions and made importable