Use signed types where necessary, and add missing functionality