Cleaning up the code.

There is plenty of redundancy.