cleaned up code, added close command