Some few changes

I sent a pull request a long time ago but it was never merged, now this pull request includes all the changes required to make this apply without conflicts.