Refactored library code to be packed in a gem