Refactoring

Added tests.