Fixing bugs mentioned by Babar Tariq