cleanup, add error codes for failures