added sam's code into it