Created separate functions for parts of evaluate

Moved code out of evaluate function for legibility