fixed warning with ?: operator (reference vs. value)
fixed warning: possible variable shadowing