refactored on function, updated docs and test cases