Completed re-code

Completely re-did the code