cleans up and adds in-function documentation