I'm struggling to see a different way of doing this. What your suggesting would work for direction, but xPos, yPos, and size all change after they are calculated initially. When the margin is applied they all change based on the relationship with each other. So we calculate size, then xPos and yPos based on size, and then we apply a margin to the values and at that time either xPos and size will change or yPos and size will change.