this needs more refactoring than i thought...