changed to use a function