refactor and further testing