Code refactor.

Fixed the errors which I could.