more error handling, cleanup and a dependency prune