fix bash: remove RANDOM
guidelines to only write to /tests
fix memleak
move pre cond