some changes to reduce memory consumption