Made the code to use SML functions