fix suboptimal code bug