access to mutable variable from closure was fixed. Code style was updated.