Improved read/unread JS function.