runtime: minor bug fixes and error checking/handling
slight formatting change