implementing elect to work with wait and priority