Refactored some code after the merge.