add tests and fix toNum