change tolerance to relative tolerance (thanks to Johannes)