Restructure for library use