Debugged, now should give proper solution