Improved logic, validation, and style