Removed unnecessary function and replaced ambiguous variables