Refactor js move to more understandable order and add comments.