Renaming redundant variables

Replaced a temporary variable with a query to avoid to much parameters
being passed around.