Cleaned up some nested if's with some functional programming.