implementing before save hook