Minor refactor and bug fixes
Correct variation algorithm