Refactored: Moving if logic into methods.