use sorted set instead
use headOption and if instead