Cleaned up with Code Sniffer. Added detailed comments.