updated to allow presave function