Change some function names and simplify flow of logic.