Add comments and make JS more readable