Refactored code to library call