Refactor python bindings