changes to db call and fixed several index errors