Revising code to clean up errors