repaired Josefs code