tools.c: bugfixes to trim functions (Phil Slack)