refactoring and choiceboxes bug fixes