refactor and adding first tests.