I think you need to handle the 24-bit case here