Moved filter code to lib