re-order functions to get rid of error