code cleanup, hopefully doesn't break anything too badly