Refactored SQL creation, Added filter for departments