more validation and bug fixes