Complete the calculation of m
Add comments

* Add debugging message
* Add comments
* Improve code readability