Add unit tests and refactor for constants and helper functions.