Be smarter about if-else statements. Fixes #146.