Improve code according to coursera feedback. use immutable collection,etc