modify for use as library