Changed Machine States numeration to match documentation. Fixed small memory leak.