refactoring some serious shit