fixed bug in building the result set