[major] refactored the code to be used as reusable library