Made friend class declarations more specific to get things compiling on gcc.
Fixed a signed/unsigned comparison.