//todo need refactoring and tests