i condensed some code here, added button functions