main m-file changed to function.