finished copying code from book 

ON TO DEBUG!