fixed algorithm to increase speed 500%