debuged validate function. is now working properly