Small refactor of functions and nested ifs.