validation function added, tests improved