fixing scope and references