refactor destructuring macro and make it much more robust