add border
fix some dimension calculation bugs