Makes filter function work with data. Also cleans up some unnecessary code and better formatting.