Optimized margin setting code. Final Bugfix Issues #7 and #8 fixed