Fixed compilation errors and bugs