Cleaned up some if-then-else code