Removed redundant code and fixed unused variables