fixed extraction, better use of return and exit codes, untested