refactored to load states and did some code cleanup