Fixed undefined variables and offsets