Fix index out of bounds. Change group of params according to Mikolaj suggestions.

Signed-off-by: Krzysztof Opasiak <ups100@tlen.pl>