various fixes, refactored SMG