test lib: cleanup
refactor index: exit with code 1 in case of error