Move stack reset function to a shared location