Removed unnecessary code for condition 1. Fixed max.