Some code cleanup and clearer comments