Fixed problem so that it runs with no null pointer  when width > height.