refactored to complete last function