refactored flexlib module