Rebase of PR 47

Rebase of #47