fixes #805 and started to work on #835