Added deep extend function as Angular.copy is not doing what we want