cleaned up code to try and make validate function work
cleaned up more