heavy refactoring of shit