bugfix and add cookie function