Abstracted the logic even more. This will require some refactoring to slim down on the number of lines (and the repetition)