General overhaul and bug fixes.