added button functionality
made code nicer