[UPDATE] Error checking added