finished debugging and function is working