refactor code

use variable x instead of i (both are increasing from 0 to 255)