Better detection and changed some floats to doubles (higher precision)