The source project of this merge request has been removed.
Fix mistakes in the original
This fixes mistakes in the original code and makes some small improvements which just make sense. Hope this helps, feel free to modify a bit more before sending to upstream, I will try to review them for you later.