moved shared code to separate functions, removed msg'ing