Moved common functions to library file