Make code cleaner and Added docstring