Putting in final version of the code - not working yet