Caps scrape together a win in Buffalo