adding console.logs at right place and fixing false bugg