smart complete function