cleaned up code for readability and removed unnecessary console prints