Debugged a few hundred lines