Fix and improve general code