Moved some functions into the library