fixed handling of margin