Use more states and function guards to clean up code