Much smarter implementation:)