See #662 (closed). This should be a complete fix, I believe.
See the ticket for an overview of my changes.