fixed bash script bugs brought on by exhaustion