reduced memory consumption
(cherry picked from commit 3068c09)