upgrading code from crap to slightly less so