Fixed bugs and made the code work

produced the corrected results