modified dict manipulation as per gaurav's new code