A big refactor