Rewrote logic for rendering buttons and add more functionality (with tests, mostly)