major reorganization/overhaul/refactor, still many buggy things