implement before save handler, see #15