code cleanup and addition of apical mode controls