Updated patch as per comment #5.