Improved drop_dim function