refactor js and fixed dupe posts