This is more of a vertical slice of the intended functionality and needs to be extended.
This commit also fixes some other bugs and cleans up related code.