Cleaned up lib functions