some refactoring done and added more comments