Yeah, there is a bunch of code duplication in that file.  I don't want to get into it right now though.