Fix numeric problems with double