more fixes, refactor tomorrow