Added an extra bit check and moved some computation to be static.