Completed thirdBits function