cleaned up king cookie code