fix remove/dereference, code simplification