optimized the multiplexer loop and deleted unnecessary parameter