Refactored all code to standalone library