added filter function and cleanup