better context handling in library javascript