refactoring

trying to abstract parts of the code