refactoring a lot of stupid shit