Made some code optimizations and fixed JS validations.