remove extraneous package imports and add error handling