Moved functions to library