removes extraneous line
moves comment next to related code
improves error handling, does minor cleanup