Refactor Capture Code And Call Format Error Function