made macro robust and fixed breaking bugs
fixed some more bugs
fixed merge conflicts