Cleaned up image filtering, added some comments