finished the function, has some issue with spec