Added a filter for results, cleaned up some of the code