fixed bugs and added index