Simplified the if-else logic a little bit to make JSLint more happy.