Fixed wrong variables scope