Fixed discardTop function