rewrite implementation of meet and join