further clean up, and a little error handling