Code clean up and added helpful comments