implemented button functions, various checks, and fixed bugs