move shape-getting code into a common function