Improper functionality of required fields function