fixed formatting and scope issue in cookie function