Updated with Friends code and fixed CR/LF's. Patched against latest code as I couldn't squash properly on my branch