Minor code reorganization

Reorganize some if's to make the code a little more clear.