mixed up h and w, added some debug messages