Cleaned up some of the code for validation