better file writing, better error handling when no link is found