before cleaning up the code, all functions work well