Fix bug in margin setting