better way to calculate spacebefore