Refactor captureMessage and captureException