formatting is not good but it works, added dependency for directory package
Added writeRaftState at the appropraite places