code refactoring

idea from http://www.reddit.com/r/programminghorror/comments/19z4jc/if_from_roguelike_unnethack/c8t32xw?context=3