Updating function documentation, some refactoring