refactors. performance issue yet unsolved