cleanup and refactor js