refactoring to pull facebook code out