added chain query optimizer