Added debug messages and fixed bug where rectangle width/height was computed incorrectly