Refactor

Restructured functions. Removed Globals. Cleaned up duplicate code. Removed the -d option to make parameter usage less confusing. Moved usage out to seperate file.