Cleaned up if-then blocks

Consolidated down to a single block of code, converted to a dictionary with lambda functions.