1. localize functions and variables
2. pre-alloc space for cookie_table
3. style fixes