second attempt at writing functions