optimization + several compilation errors fixed