Compiling but strange behaviour when running script