Fix some issues. Closes #684