Cleaned up code (prettier probably), needs test

Simplified the logic to make it easier to debug, understand
Additional testing required to ensure functionality is
properly met.