I know this is just moved code, but this method seems to really ask for some "Extract Method" refactoring. Feel free to ignore this comment.