Some code clean-up and organization