Fixes #862, Fixes #863

This is a cleanup of #864