Better puling alg. Needs refactoring
Better puling alg with corrections. Needs refactoring