Adding error checking code and cleanup
block changes