optimized some functions.