conditionally clean and build
error handling