Used polymorphism to make code simpler.

Yay Haskell!