Implemented the changes after the feedback of Nick Reed and included the
tests.