refactor facebook img code