Fix formatting
Put this function in a better place.
These were basically the same function.
Validate in a seperate function.