lib functions