refactoring done, but having some performance issues. (now benchmark takes twice the time as before