Error checking

fixed bugs