Refactor and improve REGSTATE
Handle Errors
Fix LDK => LDC
Extracted readCmd()