Debugged version 3