improved freeze function