broke code into more functions