Modified code to handle extra cases.