Redid most of the code