Extracted 'magic cookie' to class
Reformatted source code.