Reverted f9ed445c968d25e16f2200ab59ef4b2e836a284c because fix was incomplete. Reopened #599.