code cleanup, re-apply some old fixes/changes

accidently removed a few of my own changes ass-well :P