some code copy from book about scala