Added a couple of isset checks to avoid PHP notices. Fixed a few whitespace and coding style issues.