Extract some hopefully reusable stuff to extensionmethods