refactoring to use functionality as python lib