This logic is really becoming complex at this point. Can we instead move it to another class?