Fixed sifting code. Refactored code.