refactor. fix bugs
wip