Refactor state names for readability
Fix function order
Refactor variable naming