fix math and data structures