state code working tests passing very ugly