Replaced map with foreach at places not required