further improvements. code structure and validation