logical function almost done