Anonymous functions replaced with named functions to improve readability