Fixed object undefined && stack undefined problems

If you test this with a big repo, say rails you will get 2 problems:

1) at some point in time stack will be undefined (line 53)
2) object will be undefined

This will fix the problems with throwing errors, but you should probably double check if everything is ok.