updated validator, fixed some minor issues and made it more readable