Some more refactoring done here.