Solution of #39.
Added a few comments and cleaned some code.