added more logic around view with margins