Note: This is entire rewrite of this class. Simpler to look at the file ("View File" on the right upper corner) than to look at the diff.