I returned to this subject after a conversation in another thread.
I think I did much better this time. Not perfect, though: I messed up with indentations in this one:
https://github.com/rizka10/discourse/commit/d18b54628fb78bb87a6c62c021d2f31df9f261f0?diff=unified
Can you edit your pull request somehow?