refactoring to isolate pyjs