Use userid as key in filtered list to allow isset() checks
Correctly initialise $user
Fix order of arguments in array_chunk()