Refactored yesterday spaghettii code