improvement on some functions