Pull request to master

Also, please improve this body of code, it's a bit hard to understand :sweat: 
Some tips to improve the code:
* Eliminate nested `if`s
* Breakdown method into smaller methods
* As much as possible, let a method do one task only.

:bow: