Refactored code and fixed embed support for elgg 1.8