further optimized with an new variable B