[NEW] refactored to enable library calling