refactor and bring more tests online