Cleaned up margin code

Cleaning up and fixing