better handling of directories
handle failures better