updated with sage's testing code