refactor scanning