Fixed nextElement to return null if there is no next element