fixes #286

May be incomplete. Please check.