Removed redundant variables and fixed func scopes