Fixes bug part of #839