fixed bug in rectangle fitting. Achtung! copy-paste bug detected.