Instead of using switch statements for states using function pointers