updated logic and validation