Move more code to library