Add comments to explain what's happening
Put everything in a function
Add debug logs and fix program return