Optimize and fix code that draws selections and handles.