improve tests and context handling