endless script tweaking. bash sucks.