Made more general extraction method, rather than just validity check