refactor: some redundant code and dead code has been removed and some conditional statement has been fixed.