simplifications + more idiomatic scala