fixed cs, refactored a bit, still a mess