add some error recovery and factor include function call