First full set of code, but needs debugging