Error checking added