Simplifying somewhat
Adding some more input validation