Move math code to mathkit