Fixed sequence formatting code; added check for parent ID