fixed errors in last record javascript