bug fixes; more error handling; general clean up