In progress of refactoring and unittesting