try to libraryize more logic