refactor imathics.py