Divided implementation into several functions