Fixed.
Added a unit test.
Change to size_t from unsigned long.