refactor core to better organisation