move log(...)  to the end of the method.  (again, i know its not yours but you still can improve the piece of code :) )