Refactoring for simplyfing code and auto-scanning