Moved code outside of respond_to block for readability