F/rewrite groupset

Added groupset rewrite object and added tests for rewrite functionality.
copy-paste error, thanks for noting. (perhaps we should have a common refcounted ancestor class for every refcounted object? :S).