Validation and shorten

Fixed input validation and shortened the code plus some commenting