refactor core, add debug