Made minor changes, cleanup and add docstring