use switch based on first byte of key to reduce number of if statements