added close method, and much strange stuff.