Some code untangling