clean up code, add indexes for faster lookup