Code cleanup

- Put the filtering logic in a separate function.
- Only the configuration variables are upper case now.
- Improve the comments.