Improved margin implementaton