Full 9-16 bits support and a few code cleanup