changed chmod and rm position (> in case of failed run)