refactors some if else logic