another big refactor