Generic select_events function. Fixed imports.