Added test for collapse and fixed crash