Implement the actual replacement in portlets

This needs some serious refactoring, next commit
Refactoring

move the looping other every change into the result
object. This makes the replace view method a bit easier
to understand
Cleanup warnings