refine code structure and refine core calc code