refactor + debug