Debugged program to run properly