Added docstring and tidied