Final Commit. Everything is working.

Removed redundant codes and fixed some bugs.