better extraction code