Complete solution but still working on enumerable-free version