refactored print function
check out anonymous functions
added tail rec.