function working

got the function to work correctly