now it handles dynamic width and height