Fix compile error & refine code