Refactoring to make better use of dxpy library