move logic, fix bug, seems to be working