Removed unused functions & fixed scope var access