Small refactoring and fixes

We should add ajva doc for this. Can be done post merge.