SML refactored