Optimized a few scan functions.