Last of the warnings (on gcc 4.1.2 with -Wall anyway) gone - some bugs fixed as a result