Final solution with tables of chars. Terrible naming of functions, though.