Fixes/refactoring to light algo (not done)