Debugged version. Working now.