code restructure and additional logging and extraction interface added