changed output type to uint32, added checks and unit tests