Added comments explaning descisions and what the code does. Also took th...

Added comments explaining decisions and what the code does. Also took opportunity to slightly refactor the validation logic. resolves #1