created function to dynamically generate margins