Small optimizations of beginning and ending bits

The last line is an input. I am happy.