Small bug fixes. Adding comments to the code.