Bead Sort algorithm refactoring