Adding validationand bugfixes