check errors and avoid leaks
misc