Code cleanup and correct error handling put in place.