init complete nearest gallery implementation with refactored code