Remove dead code and duplication.

I cleaned up the code a bit.