fixed missing variable value problem, perhaps cleaned code