Fixed compilation errors, some optimization in compile-time and etc