Fixed #12: Console output misleading when references are updated and
some refactoring.