made formatting changes, logic is the same