Optimization: Removed expensive call to map(..) from main loop by using a lookup array.