Some refactors to remove ifs