Address pull request feedback

1. Tighten up the if else to avoid duplication
2. Add doc comments