Fixed some signed/unsigned conversion bugs