Refactor the mockapp code