Capped max beat length at 32. General refactoring.