Complete overhaul debugged but still contains logic errors.