This should fix bug 3, but still requires some refactoring for the change.