Code cleanup to handle some edge cases.