code cleanup and index fix