Refactor opdesc allocation algorithm