Fix some bugs; add cookie test