minor changes, cleanup, still buggy