implemented button functionality (rather ugly)