Refactor JTox cpp code