Documentation

- added comments
- reorganized the order and grouped functions