fixed bug in validation algorithm