added code to iterate through posts and cleaned up registering button listeners. I'm pretty sure there are probably better ways to do all this, but for now it works.