New version using interrupt function