Separate test from main module to test public api
Add documentation for `isValid`
Refactor code for better readability