debugged remaining code