Fixed bug in index() method and did more cleanup