refactoring c-to-python convert function