Generalized Code

Generalized the code and added documentation in README.md file