made save code more efficient