Fixed potential crash. Added more flexible search for command-line tools.