Refactored the code
Added the SM flag; fixes #17