Add pos() function and margin to grid code