some small improvements, safer code, nicer test command