Re-wrote read_codefile to improve reliability
Another solution for AutoOn/AutoOff