updated code for better power efficiency