Added sri's patch and a few fixes