Refactored function
Updated docs