Reorder 'modal' code for minor optimization