Cleaned up code. Added cookies.