Code cleanup.

- Added comments for all important functionality.
- Docstring added for the recognition function.