Trying to implement generic m-files solution