Removed some unnecessary code and did some refactoring.