Many changes in this commit.
1. Re-ordering of code for better aesthetics
2. Use single error() function to exit from script
3. Change wget options so it does not hang on bad server settings.