these two lines could be cleaned up to use max() instead of an if statement