lots of modifications; hope i didn't mess things up