maybe some of these checks should be factored out into helper methods -- it might be more clear what's going on. it feels like there's a lot of crufty overhead in the current code.