Fix: variable scope bug.

According to ruby doc[1]:

  Since threads are created with blocks, the same rules apply to other
  Ruby blocks for variable scope. Any local variables created within
  this block are accessible to only this thread.

Also adjust the code to match ruby style guide (Not 100% though).

[1]
http://ruby-doc.org/core-2.1.0/Thread.html#class-Thread-label-Thread+variables+and+scope