Slightly changed implementation to be in a single class with special cases.