Modified extract.py for better documentation and commenting.