fixed and close issue #1: handle case when h != w