Cleaner code + fixed scope bug.