remove tmp
extract error catching into a method