remove unused code and wire up error handling