improved context handling