fixed stack size exceeded, refactoring wip