edited with less print statements