fix file support, handle errors better in JS