defer must be here to free memory properly