Nicer implementation of firstEmptyElement