Refactored sources
Tests and refactor