Its done but needs some refactoring.