more javascript cleanup, changed sql to filter by time rather than number of entries, fixed some errors caused by bad or empty data