fixed compilation errors and removed ^M