updated the code to be easier to read