smale code refactor