Added and passed final test (plus some refactoring)