Added check on the report writer variable to try and write only in case the report writer is available