optimize rectangle drawing