updated code little'bit for imprving performance