refactored and completed the basic functionality. Added also the test