A fixed version of  #181

See comments on ce1eb4dbac780a58ae9d4bec432e0f01bfae2cc9