Much improved version of input validation. Fixed & added tests.
Build for production