refactor, taking out the print statements