improve speed: data querying and structuring