Adjusted main scan function