merging with vyara's code