Added more checks
fixes for bugs