Refactored code to standalone library