Cleaned up code formatting and ensured proper cgi encoding