Updated implementation.

Now uses a more OOP-like approach.