Moved logic over to its own file and added a helper file. #2