performance optimization via restricting unnecessary looping.