Fix runtime controller and add test coverage (fixes #1033)

Also, some minor cleanup