style changes, cleaned up error handling