May be some of you may find this useful. Second version will publish later with some refactoring and better practices.