Finished Version

Finished version with a few bugs (noted on the top of the script)