More functions, optimized some