Added user input validation and automatic cd detection.