Major cleanup, removed most C-style code