Working version of the code
- some refactoring may be done to accomodate paramater based testing