Improve drawing function, get bounding rectangle