Implemented index selection.

Also made formatting fixes