Refactored & simplified the scanning