Rebase of #404

Rebase of #404