fix related links logic
add some docs to the js code