Port original code to umbraco v6

Taken the core functionality from svn and upgraded for Umbraco v6