refactor conditional functions