modified as per Rahul comments. minor changes