Refactored the value margin controller and added test for it.