Cannot make it more generic, the code is quite similar but the conditions are actually reversed in the other method.