replace wrong memcpy calls with memset calls
Allocate/deallocate memory for storing selections instead of relying on caller's data