more error handling updates
Put rmdir outside of loop