Moved logic out of route to class and wrote unit tests