fixed some bugs. code is running, but output is problematic