Fixes for problems raised by @pingwin4eg, many thanks :)