copying parts of the official lib