minor changes and reduced stack function size