Unsigned long conversion and fix of a couple of other bugs