avoid double counting total size, modify code