validity checks added, other small changes