code cleaned up so conditions are not nested for validation