Cleaned up cookies code. Renamed cookie functions for better readability.