reorganized functions- definitions before, code after. added motor control