Moving sub pages to top pages when parent deleted

This is a bug-fixed version of #307