Copied over some library functions.