not fully tested refactor