added more stuff for remove leaves
complete but need comments