Moved more common functionality to functions and implemented basic If statements