Simpler version of Sawy's patch #1877