Refactoring compute output function