refactored core and math