More functions and fixes