tweaks to PR #22

Tweaking the code according to @stof's review.

@matthiasnoback I didn't change the `elseif`s since you had it this way before and I thought it might be the way you prefer it. Let me know if you want me to update them as well.