Updated functions for best performance