fix all functions and add all tests