turned stat calcuations into functions