Style and correctness issues, some cleanup