updated solution to use filter and maximum