Since you're in here, could you rewrite this function into a series of early returns instead of nested ifs with this huge condition?