Refactor and introduce first tests